<?php
// this line is to fix an issue we ran into here: http://stackoverflow.com/questions/7749198/getting-apc-to-play-nice-with-spl-autoload-register
// register_shutdown_function('session_write_close');

defined('MYRUN_ENV')
    || define('MYRUN_ENV', $_SERVER['MYRUN_ENV']);

/*
define('TIMESTART', microtime(true));
if (function_exists('xhprof_enable')) {
    xhprof_enable(XHPROF_FLAGS_MEMORY);
}
*/
    
// Define path to application directory
defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
    
// Define application environment
defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', $_SERVER['MYRUN_ENV']);

// Ensure library/ is on include_path
set_include_path(implode(PATH_SEPARATOR, array(
    realpath(APPLICATION_PATH . '/../library'),
    get_include_path(),
)));

define('ROOT_PATH', realpath(dirname(__FILE__) . '/../'));//base folder
define('LIBS_PATH', ROOT_PATH . '/Libs');
define('SEPARATOR', '.');

// set_include_path(PATH_SEPARATOR . get_include_path());
// echo get_include_path();
// Include Debug Functions
include_once 'Nothing/Debug.php';
/** Zend_Application */
require_once 'Zend/Application.php';
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
$startUpConfigKey = APPLICATION_ENV . '.startUpConfigKey';
Zend_Loader_Autoloader::getInstance()->registerNamespace('redis_');
// raw APC cache
$appConfig = apc_fetch($startUpConfigKey);
$appConfig = false;
if ($appConfig === false || APPLICATION_ENV == 'development') {
// if ($appConfig === false) {
    $appConfig = new Zend_Config_Ini(APPLICATION_PATH . '/modules/default/configs/' . APPLICATION_ENV . '/' . APPLICATION_ENV . '.application.ini', APPLICATION_ENV);
    apc_store($startUpConfigKey, $appConfig);
    $configKeys = apc_fetch('configuration.keys');
    $configKeys[$startUpConfigKey] = $startUpConfigKey;
    apc_store('configuration.keys', $configKeys);
}
// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    $appConfig
);

$application->bootstrap();